#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
struct ListNode
{
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};
class Solution
{
public:
    void insert(ListNode *node, int val)
    {
        if(node==NULL){node = new ListNode(val);return;};
        ListNode *tmp = new ListNode(val);
        tmp->next = node->next;
        node->next = tmp;
    };
    ListNode *reverseList(ListNode *head)
    {
        ListNode *ret = NULL;
        ListNode *ptr = head;
        while (ptr != NULL)
        {
            insert(ret, ptr->val);
            ptr = ptr->next;
        }
        return ret;
    }
};